import requests
import execjs
import json
headers = {
    'authority': 'service.kaogujia.com',
    'accept': '*/*',
    'accept-language': 'zh-CN,zh;q=0.9',
    'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzMlRLQnp1RFVlb0dYb1BBMmdIT1EiLCJzaWQiOiI2MTQ4ODc0IiwiYXVkIjoiMTAwMCIsImlzcyI6Imthb2d1amlhLmNvbSIsInR5cCI6IjEiLCJid2UiOiIwIiwibmJmIjoxNjk4MTIzOTMxLCJleHAiOjE3MDA3MTU5MzEsImlhdCI6MTY5ODEyMzkzMX0.g83DV2wdv7k5w-bPiCwKhm89cZ9TKmzWUR-5nocelyo',
    'content-type': 'application/json',
    'origin': 'https://www.kaogujia.com',
    'referer': 'https://www.kaogujia.com/',
    'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
    'version_code': '3.1',
}

params = {
    'limit': '50',
    'page': '1',
    'sort_field': 'gmv',
    'sort': '0',
}

json_data = {
    'author_type': 0,
}

response = requests.post('https://service.kaogujia.com/api/author/search', params=params, headers=headers, json=json_data).json()

data = response['data']
print(data)

js_file = open("解析.js","r",encoding="utf-8").read()
response_data = execjs.compile(js_file).call("decrypt","/api/author/search", data)
json_response_data = json.loads(response_data)

for index,item in enumerate(json_response_data['items']):
    print(item)
    print()